<template>
  <div class="home4sBox">
    <div class="box">
      <!-- //产品品类 -->
      <div class="typeList">
        <div class="typeList_header">产品品类</div>
        <div class="typeList_box">
          <div class="typeList_ul1"
               ref="btnClick"
               :style="{'left': (- transformWidth) + 'px'}">
            <div :class="{'typeList_li1': true, 'cllors': i === typeIndex}"
                 v-for="(item, i) in typeList"
                 :key="item.type"
                 @click.stop="selectTap(i)">
              <img :src=" item.img "
                   alt=""> {{item.title}}
              <img class="xhx"
                   src="../../../assets/image/home/pic11.png"
                   alt="">
            </div>

          </div>
        </div>
        <div class="type_ul2">
          <div :class=" index == typeIndex1? 'type_li2 cllors':'type_li2' "
               v-for=" (item,index) in typeList1"
               :key="index"
               @click="selectTap1(index)">{{item}}
          </div>
        </div>
        <div class="type_ul3">
          <div class="type_li3"
               v-for="(item , i ) in 17 "
               :key="i">
            <img src=""
                 alt="">
            <p>美孚</p>
          </div>
          <div class="type_li3">
            <a-icon type="ellipsis" />
            <p>更多</p>
          </div>
        </div>
      </div>
    </div>
    <div class="box1">
      <div class="journalism">
        <div :class="{'each-tab': true, 'is-active': activeValue === 1}"
             @click="activeValueChange(1)">
          <span>活动</span>
          <div class="bottom-line"></div>
        </div>
        <div :class="{'each-tab': true, 'is-active': activeValue === 2}"
             @click="activeValueChange(2)">
          <span>公告</span>
          <div class="bottom-line"></div>
        </div>
        <div :class="{'each-tab': true, 'is-active': activeValue === 3}"
             @click="activeValueChange(3)">
          <span>新手入门</span>
          <div class="bottom-line"></div>
        </div>
      </div>
      <div class="journalism_List">
        <a-collapse accordion
                    :bordered="false"
                    default-active-key="1"
                    :expand-icon-position="expandIconPosition">
          <template #expandIcon="props">
            <a-icon type="down"
                    :rotate="props.isActive ? 180 : 0" />
          </template>
          <a-collapse-panel key="1"
                            header="下一站或加盟小米 福特中国朱江离职">
            <template slot="extra">
              <img src="../../../assets/image/home/pic2.png"
                   alt="">
            </template>
            <p>{{ text }}</p>
          </a-collapse-panel>
          <a-collapse-panel key=" 2"
                            header="预计2022年夏发布 丰田GR卡罗拉要来了">
            <template slot="extra">
              <img src="../../../assets/image/home/pic2.png"
                   alt="">
            </template>
            <p>{{ text }}</p>
          </a-collapse-panel>
          <a-collapse-panel key="3"
                            header="由南京嘉远制造 松下e-Apple在日本上市">
            <template slot="extra">
              <img src="../../../assets/image/home/pic2.png"
                   alt="">
            </template>
            <p>{{ text }}</p>
          </a-collapse-panel>
          <a-collapse-panel key="4"
                            header="五菱星辰有望于2021年3季度正式上市">
            <template slot="extra">
              <img src="../../../assets/image/home/pic2.png"
                   alt="">
            </template>
            <p>{{ text }}</p>
          </a-collapse-panel>
        </a-collapse>
        <div class="collapse">更多公告</div>

      </div>
    </div>

  </div>
</template>
<script>
export default {
  data () {
    return {
      scrollTop: 0,
      typeIndex: 0,
      typeIndex1: 0,
      activeValue: 2,
      transformWidth: '',
      containerWidth: 1192,
      maxWidth: 300,
      expandIconPosition: 'right',
      text: '4月上市的全新SUPRA打响了GR品牌进入中国的第一枪，人们也由此期待更多GR的产品。之前有传言称丰田会打造GR版的卡罗拉(参数|询价)，最近这个消息就被日本媒体BestCar证实，并且他们还根据消息绘制出了详 细的假想图。从假想图上看，GR卡罗拉简直太香了！',
      typeList: [
        {
          title: '油品',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '轮胎',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '蓄电池',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '过滤系统',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '制动系统',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '点火系统',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '化学养护',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '精品',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '工具耗材',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '其他',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '平台审核',
          img: require(`../../../assets/image/home/pic1.png`)
        },
        {
          title: '注册成功',
          img: require(`../../../assets/image/home/pic1.png`)
        },
      ],
      typeList1: ['全部', '机油', '刹车油', '波箱油', '油齿'],
    }
  },
  methods: {
    selectTap (i) { //选择
      let btnClick = this.$refs.btnClick;
      let subEl = btnClick.getElementsByClassName('typeList_li1');
      let thisEl = subEl[i];
      let totalWidth = 0;
      for (let j = 0; j < subEl.length; j++) {
        totalWidth += subEl[j].offsetWidth;
      }
      let thisElLeft = thisEl.offsetLeft - btnClick.offsetLeft;
      let thisElRight = totalWidth - thisElLeft - thisEl.offsetWidth;
      let totalRemain = totalWidth - this.containerWidth;
      if (thisElLeft < this.maxWidth) {
        this.transformWidth = 0;
      } else {
        if (thisElRight < this.maxWidth) {
          this.transformWidth = totalRemain;
        } else {
          let leftRemain = thisElLeft - this.maxWidth;
          let rightRemain = thisElRight - this.maxWidth;
          if (leftRemain > rightRemain) {
            // 元素偏右
            let leftPosition = totalWidth - (thisElRight - this.maxWidth + this.containerWidth);
            this.transformWidth = leftPosition < totalRemain ? leftPosition : totalRemain;
          } else {
            // 元素偏左
            this.transformWidth = leftRemain < totalRemain ? leftRemain : totalRemain;
          }
        }
      }

      this.typeIndex = i
    },
    selectTap1 (e) {
      this.typeIndex1 = e
    },
    activeValueChange (val) {
      this.activeValue = val;
    },
    changeActivekey (key) {
      console.log(key);
    },
  },
}
</script>
<style lang="less" scoped>
.home4sBox {
  background: #fff;

  .box {
    width: @mainViewAreaWidth;
    margin: 0 auto;
    padding: 40px 0 104px;

    .typeList_header {
      font-size: 24px;
      color: @colorCommonFont;
    }

    .typeList_box {
      position: relative;
      overflow: hidden;
    }

    .typeList_ul1 {
      position: relative;
      margin-top: 24px;
      white-space: nowrap;
      width: auto;

      .typeList_li1 {
        height: 56px;
        padding: 17px 30px;
        display: inline-block;
        border-bottom: 1px solid @greyBorder;
        font-size: 16px;
        color: @colorCommonFont;
        position: relative;
        cursor: pointer;

        img {
          width: 20px;
          height: 20px;
        }

        .xhx {
          opacity: 0;
          width: 100%;
          height: 7px;
          position: absolute;
          left: 0;
          bottom: -1px;
        }
      }

      .cllors {
        color: @activeRed;
        border-bottom: none;

        .xhx {
          opacity: 1;
        }
      }
    }

    .type_ul2 {
      height: 78px;
      padding: 32px 0 32px 23px;

      .type_li2 {
        font-size: 14px;
        float: left;
        margin-right: 24px;
        cursor: pointer;
      }
    }

    .type_ul3 {
      overflow: hidden;

      .type_li3 {
        width: 185px;
        height: 86px;
        border: 1px solid @greyBorder;
        text-align: center;
        padding: 12px 0;
        margin-bottom: 16px;
        margin-right: 16px;
        float: left;

        img {
          width: 102px;
          height: 36px;
        }

        p {
          font-size: 12px;
          color: @colorCommonFont;
          margin-top: 10px;
        }

        .anticon-ellipsis {
          padding-top: 11px;
          font-size: 20px;
        }
      }

      .type_li3:nth-child(6n) {
        margin-right: 0;
      }
    }

    .cllors {
      color: @activeRed;
      border-bottom: none;
    }
  }

  .box1 {
    padding-bottom: 40px;
  }
  .floating {
    width: 78px;
    height: 342px;
    border: 1px solid @greyBorder;
    position: fixed;
    right: 20px;
    bottom: 140px;
    > div {
      width: 100%;
      height: 48px;
      border-bottom: 1px solid @greyBorder;
      font-size: 12px;
      line-height: 48px;
      text-align: center;
      background: #fff;
      cursor: pointer;
      a {
        display: inline-block;
        width: 76px;
        height: 48px;
      }
      span {
        display: inline-block;
        width: 16px;
        margin-right: 4px;
        img {
          width: 16px;
          height: 16px;
        }
      }
    }
    > div:nth-child(7) {
      border-bottom: none;
    }
  }
  .journalism {
    .flex(flex-end, center);
    font-size: 24px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    color: @colorCommonFont;
    line-height: 20px;
    margin-bottom: 20px;

    /deep/ .ant-divider {
      height: 25px;
      background: @greyBorder;
      margin: 0 41px;
      position: relative;
      top: 3px;
    }

    .each-tab {
      position: relative;
      .userUnSelect();
      cursor: pointer;
    }

    .each-tab:nth-child(2) {
      margin: 0 28px;
    }

    .bottom-line {
      width: 48px;
      height: 4px;
      opacity: 1;
      background: @activeRed;
      border-radius: 2px;
      position: absolute;
      bottom: -20px;
      left: 0;
      right: 0;
      margin: auto;
      display: none;
    }

    .is-active {
      font-size: 36px;
      font-family: PingFangSC, PingFangSC-Medium;
      font-weight: 500;
      text-align: center;
      color: @activeRed;
      line-height: 24px;

      .bottom-line {
        display: block;
      }
    }
  }

  .journalism_List {
    width: @mainViewAreaWidth;
    margin: 0 auto;
    padding-top: 72px;

    /deep/ .ant-collapse {
      background: #fff;
    }

    /deep/ .ant-collapse-content {
      background-color: @greyBackground;
      font-size: 12px;
      color: @colorGreyFont;
      border: none;
      padding-top: 18px;
    }

    /deep/ .ant-collapse-borderless > .ant-collapse-item {
      border-bottom: none;
    }

    /deep/
      .ant-collapse-icon-position-right
      > .ant-collapse-item
      > .ant-collapse-header {
      border: 1px solid @greyBorder;
    }

    /deep/ .ant-collapse > .ant-collapse-item {
      margin-bottom: 16px;
    }
  }

  .collapse {
    width: @mainViewAreaWidth;
    text-align: center;
    margin: 0 auto;
    height: 48px;
    background: #ffffff;
    border: 1px solid @greyBorder;
    line-height: 48px;
    cursor: pointer;
  }

  .ant-collapse-item-active .ant-collapse-arrow {
    color: #3b82ff !important;
  }

  /deep/
    .ant-collapse-icon-position-right
    > .ant-collapse-item
    > .ant-collapse-header
    .ant-collapse-arrow {
    color: @colorGreyFont;
  }

  /deep/
    .ant-collapse
    > .ant-collapse-item
    > .ant-collapse-header
    .ant-collapse-extra {
    float: left;
    margin-right: 10px;
  }
}
</style>
